package com.ykdl.member.kid.adapters;

import java.util.ArrayList;

import android.content.Context;
import android.content.Intent;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.RelativeLayout;

import com.lidroid.xutils.BitmapUtils;
import com.ykdl.member.kid.R;
import com.ykdl.member.kid.beans.UserActorBean;
import com.ykdl.member.kid.image.ImageOptionsFactory;
import com.ykdl.member.kid.messagebox.TheTopListActivity;
import com.ykdl.member.kid.person.PersonCenterActivity;
import com.ykdl.member.kid.widget.AsyncImageView;

public class TopUserAdapter extends BaseAdapter{

	ArrayList<UserActorBean>   list;
	private Context mContext ;
	private String TAG ;
	private BitmapUtils bitmapUtil ;
	public TopUserAdapter(Context context,String tag){
		this.mContext = context;
		TAG = tag ;
		bitmapUtil = new BitmapUtils(mContext);
		bitmapUtil.configDefaultLoadFailedImage(R.drawable.defult_user_icon);
	}
	
	public void setList(ArrayList<UserActorBean> list) {
		this.list = list;
	}
	@Override
	public int getCount() {
		// TODO Auto-generated method stub
		if (list==null) {
			return 0;
		}else {
			return list.size();
		}
	}

	@Override
	public Object getItem(int position) {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public long getItemId(int position) {
		// TODO Auto-generated method stub
		return 0;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		// TODO Auto-generated method stub
		ViewHolder holder=null;
		if (convertView==null) {
			holder = new ViewHolder();
			convertView = RelativeLayout.inflate(mContext,
					R.layout.pictureadapter_item, null);
			convertView.setTag(holder);
			holder.head = (ImageView) convertView.findViewById(R.id.head);
		}else {
			holder = (ViewHolder)convertView.getTag();
		}
		if (list.get(position).getAvatar_file_meta()!=null) {
			String url  = list.get(position).getAvatar_file_meta().getDownload_urls().getBig().getUrl();
			bitmapUtil.display(holder.head, url);
			final UserActorBean bean =list.get(position);
			holder.head.setOnClickListener(new View.OnClickListener() {
				
				@Override
				public void onClick(View v) {
					// TODO Auto-generated method stub
					Intent intent = new Intent(mContext, PersonCenterActivity.class);
					intent.putExtra(PersonCenterActivity.STR_ACTOR_ID, bean.getActor_id());
					mContext.startActivity(intent);
				}
			});
			
		}
		return convertView;
	}
	class ViewHolder {
		ImageView head;
	}
	

}
